package com.uroad.jilinpda.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.uroad.jilinpda.R;

import java.util.List;

/**
 * Created by admin(wlw) on 2018/5/25.
 */
public class BleListAdapter extends RecyclerView.Adapter<BleListAdapter.ViewHolder> {
    private Context mContext;
    private List<String> mylist;
    private OnItemClickListener onItemClickListener;
    public BleListAdapter(Context mContext, List<String> mylist) {
        this.mContext = mContext;
        this.mylist = mylist;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvContent;

        public ViewHolder(View itemView) {
            super(itemView);
            tvContent = (TextView) itemView.findViewById(R.id.tvContent);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_item_pop_common,parent, false);
        ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        String item = mylist.get(position);
        holder.tvContent.setText(item);
        if (onItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mylist.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener{
        void onItemClick(int position);
    }
}
